package com.infocollect.project.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.infocollect.project.api.entity.TappApiConfigBackEntity;
import com.infocollect.project.api.mapper.TappApiConfigBackMapper;
import com.infocollect.project.api.service.ITappApiConfigBackService;
import org.springframework.stereotype.Service;

@Service
public class TappApiConfigBackServiceImpl extends ServiceImpl<TappApiConfigBackMapper, TappApiConfigBackEntity> implements ITappApiConfigBackService {
    /**
     * 备份接口
     */
    @Override
    public void backApiConfig(TappApiConfigBackEntity entity) {
        Integer version=  baseMapper.getMaxVersion(entity.getCallMethodCode());
        if(version==null){
            version=0;
        }
        entity.setVersions(version+1);
        baseMapper.insert(entity);
    }

    /**
     * 获取指定版本的接口方法
     *
     * @param callMethodCode
     * @param versions
     * @return
     */
    @Override
    public TappApiConfigBackEntity getApiConfigVersion(String callMethodCode, Integer versions) {
        QueryWrapper<TappApiConfigBackEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("call_method_code", callMethodCode).eq("versions", versions);
        return baseMapper.selectOne(queryWrapper);
    }

    /**
     * 删除数据
     *
     * @param id
     */
    @Override
    public void delTappApiConfigBack(Long id) {
        baseMapper.deleteById(id);
    }
}
